package kTest 
{
	import constant.CampConst;
	import core.Vector2D;
	import event.HeartbeatEvent;
	import manager.UnitManager;
	import model.battle.Army;
	import model.battle.Heartbeat;
	import model.unit.AbsUnit;
	import model.unit.UnitFactory;
	/**
	 * ...
	 * @author Kylin206
	 */
	public class MoveTest extends AbsTest
	{
		
		public var army0:Army;
		public var army1:Army;
		
		protected var heartbeat:Heartbeat;
		private var factory:UnitFactory;
			
		public function MoveTest() 
		{
			factory = new UnitFactory();
			army0 = Army.lArmy;
			army1 = Army.rArmy;
			
			
			heartbeat = UnitManager.instance.heartbeat;
			heartbeat.addEventListener(HeartbeatEvent.BEAT, onHeartbeat);
			createUnit(0, CampConst.LEFT);
			createUnit(0, CampConst.RIGHT);
			
		}
		
		override public function start():void 
		{
			
		}
		
		public function onStageClick():void 
		{
			createUnit(0, CampConst.LEFT);
			
		}
		
		private var beatCountI:uint = 0;
		private function onHeartbeat(e:HeartbeatEvent):void 
		{
			beatCountI++;
			if (beatCountI % 100 == 0)
			{
				beatCountI = 0;
				createUnit(0, CampConst.RIGHT);
			}
		}
		
		private function createUnit(typeID:uint, camp:uint):AbsUnit
		{
			var unit:AbsUnit;
			unit = factory.createUnit(typeID, camp);
			var skin:Walk = new Walk();
			unit.setSkin(skin);
			Main.instance.addChild(skin);
			if(camp == CampConst.LEFT)
			{
				unit.speed = 2;
				unit.rangeR = 100;
				unit.viewR = 200;
				unit.position = new Vector2D(20, 400 + 180 * (1 + Math.random()));
				army0.addUnit(unit);
			}
			else
			{
				unit.speed = 2 + Math.random();
				unit.rangeR = 50 * (3 + Math.random());
				unit.viewR = 200 * (1 + Math.random());
				unit.position = new Vector2D(940, 400 + 180 * (1 + Math.random()));
				army1.addUnit(unit);
			}
			return unit;
		}
		
		
	}

}